<?php

namespace app\controller\admin;

use app\BaseController;
use think\response\Json;

class Product extends BaseController
{
    public function page(): Json
    {
        return $this->success($this->app->make(\app\model\Product::class)->pageData());
    }

    public function lst()
    {
        return $this->success($this->app->make(\app\model\Product::class)->getProductList());
    }
    public function save(): Json
    {
        if(!$this->request->isPost()) throw new \Exception("请求方式错误", 7001);
        return $this->success($this->app->make(\app\model\Product::class)->saveData());
    }

    public function detail(): Json
    {
        return $this->success($this->app->make(\app\model\Product::class)->detail());
    }

    public function delete()
    {
        if(!$this->request->isDelete()) throw new \Exception("请求方式错误", 7001);
        return $this->success($this->app->make(\app\model\Product::class)->del());
    }

    public function create_code(): Json
    {
        if (!$this->request->isPost()) throw new \Exception("请求方式错误", 7001);
        return $this->success($this->app->make(\app\model\ProductCode::class)->autoCreateCode());
    }

    public function code_page()
    {
        return $this->success($this->app->make(\app\model\ProductCode::class)->codePage());
    }
}
